<?php

/**
 * Albireo Kernel
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Kernel
 */
namespace KernelModule\LogsModule\PhpModule;

use KernelModule\BasePresenter;

use Nette\Environment;
use Nette\Debug;

use Albireo\FileSystem\FileException;
use KernelModule\LogsModule\LogsException;

/**
 * Presenter for processing PHP error logs (dirty to clean).
 *
 * @author     Pavel
 * @package    Kernel
 */
class ProcessPresenter extends BasePresenter {

    const displayPresenter = 'Display:';
    public $processModel;
    
    public function handleProcess(){
	$this->invalidateControl('procCount');
        //$this->redirect('this');
    }

    public function actionDefault() {
        if ($this->processModel === NULL) {
            $this->processModel = new Process();
        }
        if (!$this->processModel->workOrDirtyExist()) { //no dirty or work file
            $this->redirect($this::displayPresenter);
        }
        try {
            if ($this->processModel->processDirty()) { //whole file read
                $this->redirect($this::displayPresenter);
            } else $this->template->processed = $this->processModel->getProcessed();
        } catch (FileException $e) {
            //$this->redirect(':Kernel:Logs:', $e->getMessage());
            $this->redirect(':Kernel:Logs:Error:');
        } catch (LogsException $e) {
            $this->redirect(':Kernel:Logs:Error:fsProblem');
        }
    }

    public function renderDefault() {
        $this->showMenu();
        $this->template->title = _("Processing");
    }


}